#region - Class details -
/*  
 *  Developer   : Wicus Botha
 *  Description : 
 *  History     : WB - 2007-12-11 - Created
 */
#endregion

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;

namespace SqlServerAdmin
{
	/// <summary>
	/// Description of SqlServer.
	/// </summary>
	/// 	
	public static class SqlConst
	{
        public enum DataChangeType : byte
        {
            NoChange = 0,
            ChangedSource = 1, // action: Update S/D, Del S/D
            ChangedDestination = 2, // action: Update S/D, Del S/D
            NotInDestination = 3, // action: Add D, Del S
            NotInSource = 4 // action: Add S, Del D
        }
        public enum DataChangeAction
        {
            Add, 
            Update, 
            Delete
        }
        /* sysobjects Xtype /type
            D  = Default values
            F  = Forgein key
            FN = User functions
            PK = Primary key clustered; K = type
            P  = Store procedure
            S  = system tables
            TR = Triggers
            U  = User tables
            UQ = Unique index; K = type
            V  = View
         */
        //#region - Private variables -
        //#endregion

        #region - Private methods -
        private static string GetReplacedString(string masterString, string strParam, string strValue)
		{
			string tmpStr = masterString;
			tmpStr = tmpStr.Replace(strParam,strValue);
			return tmpStr;
		}
        #endregion
        //
        #region - Public properties / variables - 
        //
		public static string [] sqlReservedWord = new string [26] {
											"and","as","by","compute","case","create","declare","distinct","from",
											"group by","having","on","order by","procedure","select",
											"set","top","truncate table","update","when","where","with",
                                            "begin","end","if","while"
                                            };
		public static string [] sqlReservedFunc = new string [13] {
											"abs","avg","ceiling","count","dateadd","datediff",
											"datepart","floor","isnull","max","min","substring","sum"};
		public static string [] sqlReservedProc = new string [7] {
											"between","in","inner join","left join","like",
											"rigth join","rollup",};
		public static string[,] viewTablesDetail = new string[4,3] {{SqlQueries.Field_TableName,"Name","225"},//{"ID","0"},
			{"RowsCount","Row count","95"},{"TableSizeKB","Table (KB)","95"},{"IndexSizeKB","Index (KB)","95"} };

        public static string[,] viewFields = new string[9, 3] { {SqlQueries.Field_ColumnOrder,"No","30"},
            {SqlQueries.Field_ColumnName,"Field name","150"}, {SqlQueries.Field_ColumnIsIdentity,"AI","30"},
            {SqlQueries.Field_ColumnFieldType,"Field type","80"},{SqlQueries.Field_ColumnLength,"Length","50"},
            {SqlQueries.Field_ColumnPrecision,"Precision","60"},{SqlQueries.Field_ColumnScale,"Scale","50"}, 
			{SqlQueries.Field_ColumnDefaultValue,"Default value","100"},{SqlQueries.Field_ColumnIsNullable,"Nullable","60"} };
        public static string[,] viewKeys = new string[5, 3] { {"IndexId","Index Id","80"}, {"IndexName","Key name","150"},
			{"RowsCount","Row count","70"},{"TableSizeKB","Table (KB)","80"},{"IndexSizeKB","Index (KB)","80"} };
        public static string[,] viewKeysFields = new string[2, 3] { { "IndexKeyNo", "No", "30" }, { "FieldName", "Field name", "150" } };
        public static string[,] viewActiveUsers = new string[8, 3] { {"SPID","SpId","50"},//{"dbid","dbid","0"},
			{"DBName","Database","150"}, {"program_name","Application","150"},{"loginame","Login name","100"}, 
            {"hostname","Host name","100"},{"last_batch","Last batch","100"}, {"status","Status","100"}, {"cmd","Command","150"}};
		public static Color clrReservedWord = System.Drawing.Color.Blue;
		public static Color clrReservedFunc = System.Drawing.Color.Fuchsia;
		public static Color clrReservedProc = System.Drawing.Color.Green;
		#endregion

        //
        #region - Public methods - 
        public static string GetDataChangeTypeDesc(DataChangeType changeType)
        {
            switch (changeType)
            {
                case DataChangeType.NoChange : return "no change";
                case DataChangeType.ChangedSource : return "source";
                case DataChangeType.ChangedDestination : return "destination";
                case DataChangeType.NotInDestination : return "not in destination";
                case DataChangeType.NotInSource: return "not in source";
                default : return "none";
            }
        }
		public static Color GetSqlWordColor(string SqlWord)
		{
			int i = Array.BinarySearch(sqlReservedWord,SqlWord.ToLower());
			if (i >= 0)
				return clrReservedWord;
			else
			{
				i = Array.BinarySearch(sqlReservedFunc,SqlWord.ToLower());
				if (i >= 0)
					return clrReservedFunc;
				else
				{
					i = Array.BinarySearch(sqlReservedProc,SqlWord.ToLower());
					if (i >= 0)
						return clrReservedProc;
					else
						return System.Drawing.Color.Brown;
				}					
			}			
		}
        public static Color GetCompareColor(byte value)
        {
            switch ((SqlMetaData.FieldChangeType)value)
            {
                case SqlMetaData.FieldChangeType.NoChange: return Color.Black;
                case SqlMetaData.FieldChangeType.NewField: return Color.Green;
                case SqlMetaData.FieldChangeType.Deleted: return Color.Red;
                case SqlMetaData.FieldChangeType.OrderChange: return Color.DarkOrange;
                default: return Color.Navy;
            }
        }
        public static string GetCompareText(byte value)
        {
            switch ((SqlMetaData.FieldChangeType)value)
            {
                case SqlMetaData.FieldChangeType.NoChange: return "";
                case SqlMetaData.FieldChangeType.NewField: return "New field";
                case SqlMetaData.FieldChangeType.Deleted: return "Deleted";
                case SqlMetaData.FieldChangeType.OrderChange: return "Order";
                case SqlMetaData.FieldChangeType.DefValue: return "Def. value";
                case SqlMetaData.FieldChangeType.Nullable: return "Nullable";
                case SqlMetaData.FieldChangeType.DataType: return "Data type";
                case SqlMetaData.FieldChangeType.Length: return "Length";
                case SqlMetaData.FieldChangeType.Precision: return "Precision";
                case SqlMetaData.FieldChangeType.ColStat: return "Auto inc.";
                default: return "";
            }
        }
        #endregion
    }	
}

